package ovm.gui.views.load;

import ovm.entity.LoadSubjectEntity;
import ovm.gui.forms.AbstractEntityForm;
import ovm.gui.forms.EntityFormFactory;
import ovm.gui.views.AbstractEntityListView;
import ovm.management.AbstractManager;
import ovm.management.load.LoadManager;

import static ovm.application.MainApplication.navigator;

/**
 * Created by IntelliJ IDEA.
 * User: Jokser
 * Date: 14.06.12
 * Time: 23:50
 * To change this template use File | Settings | File Templates.
 */

public class LoadSubjectListView extends AbstractEntityListView {

    @Override
    protected int deleteEntity() {
        if (table.getValue() == null) {
            navigator.showNotification("Не выбран элемент.");
            return 0;
        } else {
            Integer entityId = (Integer) table.getItem(table.getValue()).getItemProperty("id").getValue();
            Object entity = AbstractManager.getAbstractEntityById(entityClass, entityId);
            if (LoadManager.persistOrDeleteLoadSubjectEntity((LoadSubjectEntity) entity, true) != 0) {
                navigator.showNotification("Произошла ошибка");
            }
            entityContainer.refresh();
        }
        return 0;
    }

    public LoadSubjectListView(Class entityClass, Boolean editable) {
        super(entityClass, editable);
        table.removeContainerProperty("details");
        setCaption("Дисциплины для нагрузки");
    }
}
